<?php
class GroupsController extends AppController {

	var $name = 'Groups';
	var $helpers = array('Html', 'Form');

	function beforeRender(){
		parent::beforeRender();
		$this->set('menu_parent', 'Users');			
		$this->set('menu_subactive', 'Groups');		
	}
	function admin_index() {
		$this->Group->recursive = 0;
		$this->set('groups', $this->paginate());
	}

	function admin_view($id = null) {
		$this->Redirect->idEmpty($id, array('action' => 'index'));
		$this->set('group', $this->Group->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->Group->create();
			if ($this->Group->save($this->data)) {
				$this->Redirect->flashSuccess('Group Saved.', array('action' => 'view', $this->Group->id));
			} else {
				$this->Redirect->flashWarning('Group could not be saved. Please try again.');				
			}
		}

	}

	function admin_edit($id = null) {
		$this->Redirect->idEmpty($id, array('action' => 'index'));
		if (!empty($this->data)) {
			if ($this->Group->save($this->data)) {
				$this->Redirect->flashSuccess('Group Saved.', array('action' => 'view', $this->Group->id));
			} else {
			  	$this->Redirect->flashWarning('Group could not be saved. Please try again.');				
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Group->read(null, $id);
		}
	}

	function admin_delete($id = null) {
		$this->Redirect->idEmpty($id, array('action' => 'index'));
		if ($this->Group->del($id)) {
			$this->Redirect->flashSuccess('Group Deleted.', array('action' => 'index'));
		}
		$this->autoRender = false;
	}
	
	function admin_search() {
		$this->Search->doSearch($this,$this->passedArgs);	
	}

	function admin_dataSearch() {
		$this->Search->redirectDataSearch($this,$this->data);
	}	

}
?>